package cn.whdream.datastructure.recursion;

import java.awt.print.Printable;

public class Queue8 {
	public int max = 8;
	public int[] array;
	public int count;
	public static void main(String[] args) {
		Queue8 q = new Queue8();
		q.check(0);
		System.out.println("算法一共"+q.count);
	}
	
	
	public Queue8() {
		super();
		this.array = new int[max];
	}
	
	public void check(int n) {
		if (n == max) {
			print();
			count++;
			return;
		}
		for (int i = 0; i < max; i++) {
			array[n] = i;
			if (judge(n)) {
				check(n+1);
			}
		}
	}

	private void print() {
		for (int i = 0; i < array.length; i++) {
			System.out.print(" "+array[i]+" ");
		}
		System.out.println();
	}


	public boolean judge(int n) {
		int val = array[n];
		//与之前所有的皇后位置做对比，有一个符合，就不可以
		for(int i = 0;i < n;i++) {
			if (array[i] == array[n] || Math.abs(i-n) == Math.abs(array[i]  - array[n]) ) {
				return false;
			}
		}
		return true;
	}
}
